<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>控制元素样式</title>
    <style>
        .d1{
            width: 100px;
            height: 100px;
            border: 1px solid hotpink;
        }
        .d2{
            width: 200px;
            height: 200px;
            border: 2px solid navy;
        }
    </style>
</head>
<body>
    <div id="div1">
        div1
    </div>
    <div id="div2">
        div2
    </div>

<script>
    var div1 = document.getElementById("div1");
    div1.onclick = function () {
        div1.style.border = "1px solid red";
        div1.style.width = "200px";
        div1.style.fontSize = "20px";
    }

    var div2 = document.getElementById("div2");
    div2.onclick = function () {
        div2.className = "d2";
    }
</script>

</body>
</html>